package com.songtao.rabbitmq.confirm;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.songtao.rabbitmq.config.RabbitConfig;
import com.songtao.rabbitmq.util.RabbitConnectionUtils;

public class Send1 {
    
    
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        
        Connection connection = RabbitConnectionUtils.getConnection();
        
        Channel channel = connection.createChannel();
        
        //声明队列
        channel.queueDeclare(RabbitConfig.QUEUE_CONFIRM_1, false, false, false, null);
        
        //消息
        String msg = "hello rabbitmq tx";
        channel.confirmSelect();
        channel.basicPublish("", RabbitConfig.QUEUE_CONFIRM_1, null, msg.getBytes());
        
        if(!channel.waitForConfirms()){
            System.out.println("发送失败");
        }else{
            System.out.println("发送成功");
        }
        
        channel.close();
        connection.close();
        
    }
}
